#include <QList>

#include "rendermanagerview.h"
#include "geometryrenderplugin.h"
#include "volumerenderplugin.h"
#include "proteinrenderplugin.h"

using namespace PBVP;

RenderManagerView::RenderManagerView(RenderManager *pRenManager, QWidget *parent)
: QTreeWidget(parent)
{
	m_pRenderManager = pRenManager;
	// Add three categories of renderer
	setColumnCount(2);
	QStringList headers;
	headers << "Name" << "Description";
	setHeaderLabels(headers);
	geoRenderers = new QTreeWidgetItem(this, QStringList(QString("Geometry Renderer")));
	volRenderers = new QTreeWidgetItem(this, QStringList(QString("Volume Renderer")));
	proRenderers = new QTreeWidgetItem(this, QStringList(QString("Protein Renderer")));
	addTopLevelItem(geoRenderers);
	addTopLevelItem(volRenderers);
	addTopLevelItem(proRenderers);
	updateAll();
}

RenderManagerView::~RenderManagerView()
{

}

//////////////////////////////////////////////////////////////////////////
// Public Slots
//////////////////////////////////////////////////////////////////////////
void RenderManagerView::updateAll()
{
	QList<GeometryRenderPlugin *> geoRenderList;
	m_pRenderManager->getGeometryRenderPlugins(geoRenderList);
	QList<VolumeRenderPlugin *>volRenderList;
	m_pRenderManager->getVolumeRenderPlugins(volRenderList);
	QList<ProteinRenderPlugin *> proRenderList;
	m_pRenderManager->getProteinRenderPlugins(proRenderList);

	GeometryRenderPlugin *pGeoRender;
	for(int i = 0; i < geoRenderList.size(); i++) {
		pGeoRender = geoRenderList[i];
		QStringList slist;
		slist << pGeoRender->name() << pGeoRender->description();
		QTreeWidgetItem *renderer = new QTreeWidgetItem(slist);
		geoRenderers->addChild(renderer);
	}

	VolumeRenderPlugin *pVolRender;
	for(int i = 0; i < volRenderList.size(); i++) {
		pVolRender = volRenderList[i];
		QStringList slist;
		slist << pVolRender->name() << pVolRender->description();
		QTreeWidgetItem *renderer = new QTreeWidgetItem(slist);
		volRenderers->addChild(renderer);
	}

	ProteinRenderPlugin *pProRender;
	for(int i = 0; i < proRenderList.size(); i++) {
		pProRender = proRenderList[i];
		QStringList slist;
		slist << pProRender->name() << pProRender->description();
		QTreeWidgetItem *renderer = new QTreeWidgetItem(slist);
		proRenderers->addChild(renderer);
	}
}